package novel.front.novellist.test;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by sutong on 2018/7/1.
 */
public class TopMusicCalculateService {
    private static List<MusicCommentMessage> ms = new ArrayList<MusicCommentMessage>();
    private static int TOP_MUSIC_COUNT =1000;

    public static List<MusicCommentMessage> getTopMusic(MusicCommentMessage mcm) {

        int topSize = ms.size();

        if (topSize == 0) {
            ms.add(mcm);
        }

        if (topSize > 0 && topSize < TOP_MUSIC_COUNT) {
            for (int j = 0; j < topSize; j++) {
                if (mcm.getCommentCount() > ms.get(j).getCommentCount()) {
                    ms.add(j, mcm);
                    break;
                }

                if (j == topSize - 1) {
                    ms.add(mcm);
                }
            }
        }

        if (topSize >= TOP_MUSIC_COUNT) {
            for (int j = 0; j < topSize; j++) {
                if (mcm.getCommentCount() > ms.get(j).getCommentCount()) {
                    ms.add(j, mcm);
                    ms.remove(topSize);
                    break;
                }
            }
        }
        return ms;
    }

}
